//
//  UIImage+GXAddition.m
//  

#import "UIImage+GXAddition.h"

@implementation UIImage (GXAddition)

- (void)gx_cornerImageWithSize:(CGSize)size fillColor:(UIColor *)fillColor radius:(CGFloat)radius completion:(void (^)(UIImage * image))completionBlock {
    //
    dispatch_async(dispatch_get_global_queue(0, 0), ^{
        UIGraphicsBeginImageContextWithOptions(size, NO, 0.0); // NO, 透明-图片被裁掉的部分，透出背景颜色。
        
        CGRect rect = CGRectMake(0, 0, size.width, size.height);
        
//        [fillColor setFill];
//        UIRectFill(rect);
        
        UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius];
        
        [path addClip];
        
        [self drawInRect:rect];
        
        UIImage * reltImg = UIGraphicsGetImageFromCurrentImageContext();
        
        UIGraphicsEndImageContext();
        
        dispatch_async(dispatch_get_main_queue(), ^{
            if (completionBlock) {
                completionBlock(reltImg);
            }
        });
    });
}

@end
